package com.cos.students.web.controller;


import com.cos.students.common.ResponseResult;
import com.cos.students.services.IRcStudentCourseService;
import com.cos.students.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cos
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/rc-student-course")
public class RcStudentCourseController {
    @Autowired
    private IRcStudentCourseService scService;

    @GetMapping("/getStudentScore")
    public ResponseResult getStudentScore(HttpServletRequest request){
        // 获取前端提供的token ,使用tokenutli进行解析
        String authorization = request.getHeader("Authorization");
        // 获取保存在jwt的token中的学员id
        Integer studentId = Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));
        return scService.getStudentScore(studentId);
    }
    @GetMapping("/showCourseTimeTable")
    public ResponseResult showCourseTimeTable(HttpServletRequest request){
        // 获取前端提供的token ,使用tokenutli进行解析
        String authorization = request.getHeader("Authorization");
        // 获取保存在jwt的token中的学员id
        Integer studentId = Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));
        return scService.showCourseTimeTable(studentId);
    }

    @PostMapping("/delCourse/{scId}")
    public ResponseResult delCourse(
            @PathVariable("scId") Integer scId,
            HttpServletRequest request) {// 这里可以使用session但我们偏偏不用哈
        // 获取前端提供的token ,使用tokenutli进行解析
        String authorization = request.getHeader("Authorization");
        // 获取保存在jwt的token中的学员id
        Integer studentId = Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));
        return scService.delCourse(scId);
    }
    @PostMapping("/selectCourse/{courseId}")
    public ResponseResult selectCourse(
            @PathVariable("courseId") Integer courseId,
            HttpServletRequest request) {// 这里可以使用session但我们偏偏不用哈
        // 获取前端提供的token ,使用tokenutli进行解析
        String authorization = request.getHeader("Authorization");
        // 获取保存在jwt的token中的学员id
        Integer studentId = Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));
        return scService.addStudentCourse(courseId, studentId);
    }

    @GetMapping("/getStudentCourse")
    public ResponseResult getStudentCourse(HttpServletRequest request) {
        String authorization = request.getHeader("Authorization");
        // 获取保存在jwt的token中的学员id
        Integer studentId = Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));

        return scService.getStudentCourse(studentId);


    }

}
